{extend name='public/content'}

{block name="title"}
	保存用户信息
{/block}

{block name="body"}
<form action="{:url('outlo/saveuserinfo')}" method="post">

<div style="position:relative">
    <div class="uploadimage" 
    style="background-image: url({$info.logo});" 
    	data-tips-image="{$info.logo}"><input type="hidden" name="logo" value="{$info.logo}"></div>
	<input type="file" name="" style="display: none" id="btn_file">
	<div class="uploadfilemylogo btn">上传头像</div>
</div>
昵称
<input type="text" name="nickname" value="{$info.nickname}">
//电话号码
<!-- <input type="text" name="mobile" value="{$info.mobile}"> -->
真实姓名
<input type="text" name="realname" value="{$info.realname}">
/性别
<input type="radio" name="sex" value="0">保密
<input type="radio" name="sex" value="1">男
<input type="radio" name="sex" value="2">女

<button >保存</button>
</form>
<a href="{:url('index/user/index')}">我的</a>
{/block}

{block name="script"}
<!-- <script type="text/javascript" href="/static/index/md5.js"></script> -->
 	<script type="text/javascript">
 		require(['jquery',"md5"], function () {
		  

		    $(".uploadfilemylogo").click(function(event) {
		    	 document.getElementById("btn_file").click(); 
		    });

		    $('#btn_file').change(function(){
		    	var thispic=$(this);
		 		var fileinpt = $(this)[0].files[0];
		 	    var data = new FormData();
		 	   		$.each($(this)[0].files, function(i, file) {
			            data.append('file', file);
			    	});

		    	$.ajax({ 
	                  type : "post",  
	                  url : "{:url('admin/plugs/uploadfilebyerdao')}",  
	                  data : data,  
	                  dataType : "json", 
	                  cache: false,
	                  contentType: false,     //不可缺参数
            		  processData: false,     //不可缺参数
	                  success : function(src){
	                  	  if(src.status==1){
	                  	  	$("input[name=file]").val(src.data);
	                  	  	$("input[name=logo]").val(src.data);
	                  	  	$(".uploadimage").css('backgroundImage', 'url(' + src.data + ')');
	                  	  }	
	                  }  
	             });

		    })










		    $('#btn_file1').change(function(){
		 		var thispic=$(this);
		 		var file = $(this)[0].files[0];
		 	    var data = new FormData();

		 	    $.each($('#user_img')[0].files, function(i, file) {
			            data.append('Filedata', file);
			    });


		 		console.log(file);	
			    if((file.type).indexOf("image/")==-1){  
			   		alert("请上传图片"); 
			   		return ;
			    }  
  			 	var id = "upfile"+Math.random();
  			 	var md5s  = hex_md5(file.name);
				var data ={
					id:id,
					md5:md5s,
					uptype:"qiniu",
					filename:file.name
				}
				
				 $.ajax({ 
	                  type : "post",  
	                  url : "{:url('admin/plugs/upstate')}",  
	                  data : data,  
	                  dataType : "json",  
	                  success : function(src){
	                  		uploadfile(src);
	                  }  
	             });

				 function uploadfile(data){
				 	var filename =data.data.file_url;
				 	var index1=filename.lastIndexOf(".");  
					var houzhui = filename.toLowerCase().split('.').splice(-1);

					// var index2=filename.length; 
					// var postf=filename.substring(index1,index2);
					var key = 	md5s+"."+houzhui;
					//console.log(data.data);return;
					var formData = new FormData()
					    formData.append('file', file);
						formData.append('token', data.data.token);
						formData.append('success_action_status', 200);
						formData.append('id', id);
						formData.append('md5', md5s);
						formData.append('key', key);
						formData.append('type', file.type);
						formData.append('name', file.name);
						formData.append('size', file.size);
						formData.append('lastModifiedDate', file.lastModifiedDate);	

						$.ajax({ 
		                  type : "post",  
		                  url  : data.data.server,  
		                  data : formData, 
		                  processData: false, 
		                  dataType : "json",  
		                  success : function(dat){
		                  		console.log(dat);
		                  }  
	             });	
				 }



		 			// var reader = new FileReader();
				    //         reader.readAsDataURL(file);
				    //          reader.onload = function ( event ) { 
					   //        var baase64 = event.target.result;
					   //        alert(baase64);
					   //        	// $.ajax({ 
					   //         //        type : "post",  
					   //         //        url : "{{URL::to('adarticle/savepic')}}",  
					   //         //        data : {data:baase64},  
					   //         //        dataType : "json",  
					   //         //        success : function(src){
					   //         //        	var datafile = thispic.attr('data-file');
					   //         //          $("#"+datafile)[0].value=src.data.name;
					   //         //        }  
					   //         //   });
					   //      };
		 	})
		});
 	</script>
{/block}

{block name="style"}
 <style type="text/css">
 	
 </style>
{/block}